//****************************************************
// Porman Project 2
// Filename: CStateObject.h
// Date: 2009/02/17
// Author: KengYu Lin
// Modify:
//****************************************************
#include "CGLDef.h"
#include "CStateObject.h"

namespace Porman
{

namespace GL
{
//
// class CAlphaStateObject
//
CAlphaStateObject::CAlphaStateObject( const CAlphaStateObject& l )
{
    (*this) = l;
}

CAlphaStateObject& CAlphaStateObject::operator=( const CAlphaStateObject& l )
{
    m_bEnable = l.m_bEnable;
    m_fAlphaRef = l.m_fAlphaRef;
    m_eCmpFunc = l.m_eCmpFunc;
    return (*this);
}

bool CAlphaStateObject::operator==( const CAlphaStateObject& l )
{
    return !((*this) != l);
}

bool CAlphaStateObject::operator!=( const CAlphaStateObject& l )
{
    if( m_bEnable != l.m_bEnable ||
        m_fAlphaRef != l.m_fAlphaRef ||
        m_eCmpFunc != l.m_eCmpFunc )
        return true;
    else
        return false;
}

void CAlphaStateObject::reset( void )
{
    m_bEnable = false;
    m_fAlphaRef = 0;
    m_eCmpFunc = E_CMPFUNC_ALWAYS;
}

//
// class CBlendStateObject
//
CBlendStateObject::CBlendStateObject( const CBlendStateObject& l )
{
    (*this) = l;
}

CBlendStateObject& CBlendStateObject::operator=( const CBlendStateObject& l )
{
    m_bEnable = l.m_bEnable;
    m_eBlendOp = l.m_eBlendOp;
    m_eSrcBlendFactor = l.m_eSrcBlendFactor;
    m_eDstBlendFactor = l.m_eDstBlendFactor;
    return (*this);
}

bool CBlendStateObject::operator==( const CBlendStateObject& l )
{
    return !((*this) != l);
}

bool CBlendStateObject::operator!=( const CBlendStateObject& l )
{
    if( m_bEnable != l.m_bEnable ||
        m_eBlendOp != l.m_eBlendOp ||
        m_eSrcBlendFactor != l.m_eSrcBlendFactor ||
        m_eDstBlendFactor != l.m_eDstBlendFactor )
        return true;
    else
        return false;
}

void CBlendStateObject::reset( void )
{
    m_bEnable = false;
    m_eBlendOp        = E_BLENDOP_ADD;
    m_eSrcBlendFactor = E_BLENDFACTOR_ONE;
    m_eDstBlendFactor = E_BLENDFACTOR_ZERO;
}

//
//class CDepthStateObject
//
CDepthStateObject::CDepthStateObject( const CDepthStateObject& l )
{
    (*this) = l;
}

CDepthStateObject& CDepthStateObject::operator=( const CDepthStateObject& l )
{
    m_bEnable = l.m_bEnable;
    m_eCmpFunc = l.m_eCmpFunc;
    return (*this);
}

bool CDepthStateObject::operator==( const CDepthStateObject& l )
{
    return !((*this) != l);
}

bool CDepthStateObject::operator!=( const CDepthStateObject& l )
{
    if( m_bEnable != l.m_bEnable ||
        m_eCmpFunc != l.m_eCmpFunc )
        return true;
    else
        return false;
}

void CDepthStateObject::reset( void )
{
    m_bEnable = false;
    m_eCmpFunc = E_CMPFUNC_LESS;
}

//
//class CStencilStateObject
//
CStencilStateObject::CStencilStateObject( const CStencilStateObject& l )
{
    (*this) = l;
}

CStencilStateObject& CStencilStateObject::operator=( const CStencilStateObject& l )
{
    m_bEnable = l.m_bEnable;
    m_iStencilRef = l.m_iStencilRef;
    m_uiStencilMask = l.m_uiStencilMask;
    m_eStencilFail = l.m_eStencilFail;
    m_eDepthFail = l.m_eDepthFail;
    m_eDepthStencilAllPass = l.m_eDepthStencilAllPass;
    m_eFaceType = l.m_eFaceType;
    m_eCmpFunc = l.m_eCmpFunc;
    return (*this);
}

bool CStencilStateObject::operator==( const CStencilStateObject& l )
{
    return !((*this) != l);
}

bool CStencilStateObject::operator!=( const CStencilStateObject& l )
{
    if( m_bEnable != l.m_bEnable ||
        m_iStencilRef != l.m_iStencilRef ||
        m_uiStencilMask != l.m_uiStencilMask ||
        m_eStencilFail != l.m_eStencilFail ||
        m_eDepthFail != l.m_eDepthFail ||
        m_eDepthStencilAllPass != l.m_eDepthStencilAllPass ||
        m_eFaceType != l.m_eFaceType ||
        m_eCmpFunc != l.m_eCmpFunc )
        return true;
    else
        return false;
}

void CStencilStateObject::reset( void )
{
    m_bEnable = false;

    m_iStencilRef = 0;
    m_uiStencilMask = 0x11111111;

    m_eStencilFail         = E_STENCILOP_KEEP;
    m_eDepthFail           = E_STENCILOP_KEEP;
    m_eDepthStencilAllPass = E_STENCILOP_KEEP;
    m_eFaceType            = E_FACE_FRONTBACK;
    m_eCmpFunc             = E_CMPFUNC_LESS;
}

//
//class CScissorStateObject
//
CScissorStateObject::CScissorStateObject( const CScissorStateObject& l )
{
    (*this) = l;
}

CScissorStateObject& CScissorStateObject::operator=( const CScissorStateObject& l )
{
    m_bEnable = l.m_bEnable;
    m_iX = l.m_iX;
    m_iY = l.m_iY;
    m_iWidth = l.m_iWidth;
    m_iHeight = l.m_iHeight;
    return (*this);
}

bool CScissorStateObject::operator==( const CScissorStateObject& l )
{
    return !((*this) != l);
}

bool CScissorStateObject::operator!=( const CScissorStateObject& l )
{
    if( m_bEnable != l.m_bEnable ||
        m_iX != l.m_iX ||
        m_iY != l.m_iY ||
        m_iWidth != l.m_iWidth ||
        m_iHeight != l.m_iHeight )
        return true;
    else
        return false;
}

void CScissorStateObject::reset( void )
{
    m_bEnable = false;
    m_iX = m_iY = 0;
    m_iWidth = 1024;
    m_iHeight = 768;
}

//
// class CCullFaceStateObject
//
CCullFaceStateObject::CCullFaceStateObject( const CCullFaceStateObject& l )
{
    (*this) = l;
}

CCullFaceStateObject& CCullFaceStateObject::operator=( const CCullFaceStateObject& l )
{
    m_bEnable = l.m_bEnable;
    m_eFaceType = l.m_eFaceType;
    m_eCullFace = l.m_eCullFace;
    return (*this);
}

bool CCullFaceStateObject::operator==( const CCullFaceStateObject& l )
{
    return !((*this) != l);
}

bool CCullFaceStateObject::operator!=( const CCullFaceStateObject& l )
{
    if( m_bEnable != l.m_bEnable ||
        m_eFaceType != l.m_eFaceType ||
        m_eCullFace != l.m_eCullFace )
        return true;
    else
        return false;
}

void CCullFaceStateObject::reset( void )
{
    m_bEnable = false;
    m_eFaceType = E_FACE_BACK;
    m_eCullFace = E_CULLFACE_CCW;
}

//
// class CPolygonOffsetStateObject
//
CPolygonOffsetStateObject::CPolygonOffsetStateObject( const CPolygonOffsetStateObject& l )
{
    (*this) = l;
}

CPolygonOffsetStateObject& CPolygonOffsetStateObject::operator=( const CPolygonOffsetStateObject& l )
{
    m_bEnable = l.m_bEnable;
    m_fFactor = l.m_fFactor;
    m_fUnits = l.m_fUnits;
    return (*this);
}

bool CPolygonOffsetStateObject::operator==( const CPolygonOffsetStateObject& l )
{
    return !((*this) != l);
}

bool CPolygonOffsetStateObject::operator!=( const CPolygonOffsetStateObject& l )
{
    if( m_bEnable != l.m_bEnable ||
        m_fFactor != l.m_fFactor ||
        m_fUnits != l.m_fUnits )
        return true;
    else
        return false;
}

void CPolygonOffsetStateObject::reset( void )
{
    m_bEnable = false;
    m_fFactor = 0;
    m_fUnits = 0;
}

//
// class CPolygonModeStateObject
//
CPolygonModeStateObject::CPolygonModeStateObject( const CPolygonModeStateObject& l )
{
    (*this) = l;
}

CPolygonModeStateObject& CPolygonModeStateObject::operator=( const CPolygonModeStateObject& l )
{
    m_eFaceType = l.m_eFaceType;
    m_eMode = l.m_eMode;
    return (*this);
}

bool CPolygonModeStateObject::operator==( const CPolygonModeStateObject& l )
{
    return !((*this) != l);
}

bool CPolygonModeStateObject::operator!=( const CPolygonModeStateObject& l )
{
    if( m_eFaceType != l.m_eFaceType ||
        m_eMode != l.m_eMode )
        return true;
    else 
        return false;
}

void CPolygonModeStateObject::reset( void )
{
    m_eFaceType = E_FACE_FRONTBACK;
    m_eMode = E_POLYGONMODE_FILL;
}

}//End namespace GL

}//End namespace Porman